package org.railage.server.dao;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.Session;
import org.railage.server.entities.Passenger;
import org.railage.server.util.HibernateUtil;

public class PassengerDAOImpl implements PassengerDAO {

	private static final Logger log = Logger.getLogger(PassengerDAOImpl.class);

	@SuppressWarnings("unchecked")
	public List<Passenger> getPassengersByTrip(int tripID) {
		Session session = null;
		List<Passenger> passengers = null;
		try {
			session = HibernateUtil.getSessionFactory().openSession();
			Query query = session.getNamedQuery("getPassengersByTrip");
			query.setInteger("id_trip", tripID);
			passengers = (List<Passenger>) query.list();
		} catch (Exception e) {
			log.error("Error occured during Hibernate session:", e);
		} finally {
			if (session != null && session.isOpen()) {
				session.close();
			}
		}
		return passengers;
	}

}
